package com.dhcc.sdc.base.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.sdc.base.entity.SdcBaseAssessmenlinkEntity;
import com.dhcc.sdc.base.service.ISdcBaseAssessmenlinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 评估表与项目关联表
 * 
 * @ClassName: SdcBaseAssessmenlinkController
 * @Description: TODO
 * @author sunyingjie
 * @date 2022-02-14 10:31:26
 */
@Controller
@RequestMapping("${sys.backendPath}/base/sdcbaseassessmenlink")
public class SdcBaseAssessmenlinkController extends BaseController {

	private String PREFIX = "/backend/base/sdcbaseassessmenlink/";

	@Autowired
	private ISdcBaseAssessmenlinkService sdcBaseAssessmenlinkService;
	

    /**
     * 跳转到评估表与项目关联表列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdcbaseassessmenlink.html";
    }
	
    /**
     * 跳转到新增评估表与项目关联表
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdcbaseassessmenlink_add.html";
    }
	
	/**
     * 跳转到修改评估表与项目关联表
     */
    @RequestMapping("/to_update/{sdcBaseAssessmenlinkId}")
    public String toUpdate(@PathVariable Long sdcBaseAssessmenlinkId, Model model) {
        SdcBaseAssessmenlinkEntity sdcBaseAssessmenlink = this.sdcBaseAssessmenlinkService.selectById(sdcBaseAssessmenlinkId);
        model.addAttribute("sdcBaseAssessmenlink",sdcBaseAssessmenlink);
        return PREFIX + "sdcbaseassessmenlink_edit.html";
    }

    /**
     * 获取评估表与项目关联表列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdcBaseAssessmenlinkEntity> page = new PageFactory<SdcBaseAssessmenlinkEntity>().defaultPage();
        List<SdcBaseAssessmenlinkEntity> result = this.sdcBaseAssessmenlinkService.page(page,params);
        page.setRecords((List<SdcBaseAssessmenlinkEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增评估表与项目关联表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdcBaseAssessmenlinkEntity sdcBaseAssessmenlink) {
        if (CommonUtil.isOneEmpty(sdcBaseAssessmenlink)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdcBaseAssessmenlink.insert();
        return R.ok();
    }

    /**
     * 删除评估表与项目关联表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdcBaseAssessmenlinkId) {
	
        this.sdcBaseAssessmenlinkService.deleteById(sdcBaseAssessmenlinkId);

        return R.ok();
    }

    /**
     * 修改评估表与项目关联表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdcBaseAssessmenlinkEntity sdcBaseAssessmenlink) {
        if (CommonUtil.isOneEmpty(sdcBaseAssessmenlink)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdcBaseAssessmenlinkEntity old = this.sdcBaseAssessmenlinkService.selectById(sdcBaseAssessmenlink.getId());

        old.setAsmtId(sdcBaseAssessmenlink.getAsmtId());
        old.setItemId(sdcBaseAssessmenlink.getItemId());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
